from PyQt4.QtGui import QApplication
import dbus.service
import sys, os
from dbus.mainloop.qt import DBusQtMainLoop
from ignoreList import IgnoreList
from conf import Config
 
class DbusService(dbus.service.Object):
    def __init__(self):
        busName = dbus.service.BusName('org.LinRemote.Server', bus = dbus.SessionBus())
        dbus.service.Object.__init__(self, busName, '/org/LinRemote/Server')
    
    @dbus.service.method('org.LinRemote.Server')
    def exit(self): sys.exit()
    
    @dbus.service.method('org.LinRemote.Server')
    def addToIgnoreList(self, IP):
        IgnoreList().addToList(IP)
        
    @dbus.service.method('org.LinRemote.Server')
    def reloadIgnoreList(self):
        IgnoreList().reload()
        
    @dbus.service.method('org.LinRemote.Server')
    def reloadCFG(self):
        Config.reload()
        
    @dbus.service.method('org.LinRemote.Server')
    def pwd(self):
        return os.getcwd()
    
def run():
    DBusQtMainLoop(set_as_default = True)
    app = QApplication(sys.argv)
    calc = DbusService()
    sys.exit(app.exec_())